/**
 * 图标映射工具
 * 用于将Font Awesome图标映射到UnoCSS Carbon图标
 */

export interface IconMapping {
  [key: string]: string
}

// Font Awesome 到 UnoCSS Carbon 图标的映射
export const iconMapping: IconMapping = {
  // 导航相关
  'fa-home': 'i-carbon-home',
  'fa-search': 'i-carbon-search',
  'fa-compass': 'i-carbon-compass',
  'fa-book': 'i-carbon-book',
  'fa-user': 'i-carbon-user',
  'fa-user-circle': 'i-carbon-user-avatar',

  // 箭头相关
  'fa-chevron-left': 'i-carbon-chevron-left',
  'fa-chevron-right': 'i-carbon-chevron-right',
  'fa-arrow-left': 'i-carbon-chevron-left',
  'fa-arrow-right': 'i-carbon-chevron-right',
  'fa-arrow-up-left': 'i-carbon-arrow-up-left',

  // 操作相关
  'fa-times': 'i-carbon-close',
  'fa-close': 'i-carbon-close',
  'fa-times-circle': 'i-carbon-close',
  'fa-ellipsis-h': 'i-carbon-overflow-menu-horizontal',
  'fa-ellipsis-v': 'i-carbon-overflow-menu-vertical',
  'fa-download': 'i-carbon-download',
  'fa-share': 'i-carbon-share',
  'fa-share-alt': 'i-carbon-share',

  // 交互相关
  'fa-thumbs-up': 'i-carbon-thumb-up',
  'fa-thumbs-o-up': 'i-carbon-thumb-up',
  'fa-comment': 'i-carbon-chat',
  'fa-comments': 'i-carbon-chat',
  'fa-heart': 'i-carbon-heart',
  'fa-bookmark': 'i-carbon-bookmark',
  'fa-star': 'i-carbon-star',
  'fa-star-o': 'i-carbon-star',

  // 状态相关
  'fa-spinner': 'i-carbon-loading',
  'fa-circle-o-notch': 'i-carbon-loading',
  'fa-check': 'i-carbon-checkmark-filled',
  'fa-check-circle': 'i-carbon-checkmark-filled',
  'fa-play': 'i-carbon-play-filled',
  'fa-play-circle': 'i-carbon-play-filled',
  'fa-lock': 'i-carbon-locked',
  'fa-lock-alt': 'i-carbon-locked',
  'fa-exclamation-triangle': 'i-carbon-warning',
  'fa-exclamation-circle': 'i-carbon-warning',
  'fa-wifi': 'i-carbon-signal',
  'fa-signal': 'i-carbon-signal',
  'fa-battery-full': 'i-carbon-battery-full',

  // 内容相关
  'fa-file': 'i-carbon-document',
  'fa-file-o': 'i-carbon-document',
  'fa-file-text': 'i-carbon-document',
  'fa-file-alt': 'i-carbon-document',
  'fa-folder': 'i-carbon-folder',
  'fa-folder-open': 'i-carbon-folder-open',
  'fa-filter': 'i-carbon-filter',
  'fa-trash': 'i-carbon-trash-can',
  'fa-trash-o': 'i-carbon-trash-can',
  'fa-edit': 'i-carbon-edit',
  'fa-pencil': 'i-carbon-edit',
  'fa-cog': 'i-carbon-settings',
  'fa-cogs': 'i-carbon-settings',
  'fa-sign-out': 'i-carbon-logout',
  'fa-sign-out-alt': 'i-carbon-logout',

  // 时间相关
  'fa-clock': 'i-carbon-time',
  'fa-clock-o': 'i-carbon-time',
  'fa-calendar': 'i-carbon-calendar',
  'fa-calendar-alt': 'i-carbon-calendar',

  // 视图相关
  'fa-eye': 'i-carbon-view',
  'fa-eye-slash': 'i-carbon-view-off',
  'fa-list': 'i-carbon-list',
  'fa-th': 'i-carbon-grid',
  'fa-th-large': 'i-carbon-grid',

  // 社交相关
  'fa-bell': 'i-carbon-notification',
  'fa-envelope': 'i-carbon-email',
  'fa-phone': 'i-carbon-phone',
  'fa-map-marker': 'i-carbon-location',
}

/**
 * 获取对应的UnoCSS图标类名
 * @param iconKey 原始图标名称
 * @returns UnoCSS图标类名
 */
export function getIconClass(iconKey: string): string {
  // 移除fa-前缀
  const cleanKey = iconKey.replace(/^fa-/, '')
  const fullKey = `fa-${cleanKey}`

  // 查找映射
  return iconMapping[fullKey] || iconMapping[iconKey] || `i-carbon-${cleanKey}`
}

/**
 * 转换图标名称数组
 * @param icons 图标名称数组
 * @returns 转换后的图标类名数组
 */
export function convertIcons(icons: string[]): string[] {
  return icons.map(icon => getIconClass(icon))
}

/**
 * 常用图标快捷方式
 */
export const commonIcons = {
  // Tab导航图标
  home: 'i-carbon-home',
  search: 'i-carbon-search',
  compass: 'i-carbon-compass',
  book: 'i-carbon-book',
  user: 'i-carbon-user-avatar',

  // 操作图标
  back: 'i-carbon-chevron-left',
  forward: 'i-carbon-chevron-right',
  close: 'i-carbon-close',
  more: 'i-carbon-overflow-menu-horizontal',
  download: 'i-carbon-download',
  share: 'i-carbon-share',
  like: 'i-carbon-thumb-up',
  comment: 'i-carbon-chat',
  favorite: 'i-carbon-heart',
  bookmark: 'i-carbon-bookmark',

  // 状态图标
  loading: 'i-carbon-loading',
  success: 'i-carbon-checkmark-filled',
  error: 'i-carbon-warning',
  locked: 'i-carbon-locked',
}

export default commonIcons